#ifndef _DEBUG_H_
#define _DEBUG_H_

#  include <stdio.h>
#  ifndef DEBUG_FP
#   define DEBUG_FP    stdout
#  endif

#define _PRINT_EXIT( ... ) {printf(__VA_ARGS__);exit(-1);}

# ifdef DEBUG /* DEBUG */

#  define ASSERT( exp ) {\
	if(!(exp)) {\
		fprintf(DEBUG_FP, "!! Assert failed. [%-12s:%3d] '" #exp "'\n", __FILE__, __LINE__); \
	}\
}

#  define ASSERT_NULL( exp ) {\
	if( exp ) {\
		fprintf(DEBUG_FP, "!! Assert failed. [%-12s:%3d] '" #exp "'\n", __FILE__, __LINE__); \
	}\
}


#  define DEBUG_PRINTF( str , ... )  do { \
          fprintf(DEBUG_FP, "[%-12s:%3d] " str, __FILE__, __LINE__, __VA_ARGS__); \
      } while (0)
#  define DBG(x)  do { DEBUG_PRINTF("%s\n", #x); x; } while (0)
# else /* !DEBUG */
#  define DEBUG_PRINTF(fmt, ...) 
#  define DBG(x) 
#  define ASSERT( exp )
#  define ASSERT_NULL( exp )
# endif /* !DEBUG */

# ifdef TASKDEBUG
#  define PRINTF_FOR_TESTING( ... ) printf(__VA_ARGS__)
# else
#  define PRINTF_FOR_TESTING( ... )
# endif

#define SLOW_DOWN() do{ \
	int i=0; \
	for(i=0; i < 10000000; i++) \
	for(i=0; i < 10000000; i++) \
	for(i=0; i < 10000000; i++){} \
}while(0)

#endif
